package com.ebupt.migu.music.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;


@Configuration
public class SftpThreadPoolConfig {

    @Bean(name = "sftpThreadPool")
    public ThreadPoolTaskExecutor  threadPool() {
        // 根据需求调整核心线程数、最大线程数、队列大小和存活时间
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5); // 核心线程数
        executor.setMaxPoolSize(7); // 最大线程数
        executor.setQueueCapacity(10); // 队列容量
        executor.setKeepAliveSeconds(30); // 线程活动时间
        executor.setThreadNamePrefix("sftpThreadPool-"); // 线程名前缀
        executor.setRejectedExecutionHandler(new java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy()); // 拒绝策略
        executor.initialize(); // 初始化
        return executor;
    }
}